<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 	<title>${title }</title>
	<!--自定义index样式-->
	<link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" />
	<link rel="stylesheet" href="${ctx }/static/styles/edit/box.css" />
	<!--js库-->
	<%@ include file="/static/commons/jquery-easyui.jsp" %>
	<script language="JavaScript" src="${ctx}/static/widgets/easyui/plugins/jquery.draggable.js"></script>
	<script language="JavaScript" src="${ctx}/static/widgets/easyui/plugins/jquery.droppable.js"></script>
	<script language="JavaScript" src="${ctx}/static/widgets/easyui/plugins/jquery.tree.js"></script>
	<script language="JavaScript" src="${ctx}/static/scripts/set_select.js"></script>
	<script language="javascript"src="${ctx}/static/scripts/WdatePicker/WdatePicker.js"></script>
	<style type="text/css">
		#selectTr dl{width: 99%; margin-top: 4px;}
		#selectTr dl:nth-child(odd){background-color: #f34e3a; color: #fff;}
		#selectTr dl dt{padding: 5px;}
		#selectTr dl dd{min-width: 60px; display: inline-block; padding: 4px; margin-left: 15px;}
		#selectTr dl dt *, #selectTr dl dd *{cursor: pointer;}
	</style>
  </head>
  
  <body style="padding-bottom:8px;">
  		<c:set var="em" value="<span>*</span>"></c:set>
  		<c:set var="disabled" value=""></c:set>
  		<c:set var="ifSelect" value=""></c:set>
  		<c:set var="noChange" value=""></c:set>
  		<c:set var="isImportant" value="true"></c:set>
  		<c:set var="deptCode" value=""></c:set>
  		<c:if test="${not empty view}">
  			<c:set var="disabled" value="disabled"></c:set>
  			<c:set var="ifSelect" value="false"></c:set>
  			<c:set var="em" value=""></c:set>
  			<c:set var="isImportant" value=""></c:set>
  		</c:if>
  		<c:if test="${not empty role.user_id}">
	  		<c:set var="noChange" value="disabled"></c:set>
  		</c:if>
  		<form id="editForm" action="${ctx}/notice/save" method="post">
  			<input type="hidden" value="${obj.notice_id}" id="noticeId" name="p_noticeId" />
  			<div class="box">
	  			<table cellspacing="0" cellpadding="0">
	  				<tbody>
						<tr>
							<td class="message">
								<p><span>*</span>通知标题：</p>
							</td>
							<td colspan="3">
								<input type="text" id="noticeTitle" name="p_noticeTitle" value="${obj.notice_title }"
									class="wd170 " ${disabled } maxLength="42" style="width: 100%;" />
							</td>
						</tr>
						<tr>
							<td class="message">
								<p><span>*</span>通知日期：</p>
							</td>
							<td>
								<input type="text" id="noticeDate" name="p_noticeDate" value="${not empty obj.notice_date_ ? obj.notice_date_ : now }"
									onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false,readOnly:true})"  ${disabled } 
									class="wd170 Wdate" style="width: 180px;" />
							</td>
							<td class="message">
								<p><span>*</span>查看类型：</p>
							</td>
							<td style="width: 180px;">
								<vvise:select id="noticeUser" name="p_noticeUser" sqlname="getCodeData" className="wd170" width="99%"
	  								onchange="showUser" defval="${obj.notice_user}" sqlparam="notice_user" default="false" ifSelect="${ifSelect}" />
							</td>
						</tr>
						<tr>
							<td class="message">
								<p><span>*</span>通知内容：</p>
							</td>
							<td colspan="3">
								<textarea class="textareas"  ${disabled } id="noticeDesc" name="p_noticeDesc">${obj.notice_desc }</textarea>
							</td>
						</tr>
						
						<tr id="selectTr" <c:if test="${obj.notice_user ne 2}">style="display: none;"</c:if> >
							<td class="message">
								<p><span>*</span>通知人员：</p>
							</td>
							<td colspan="3" style="padding: 3px;text-align: left;">
								<c:choose>
									<c:when test="${not empty view}">
										<!-- 查看 -->
										<c:set var="deptCode" value=""></c:set>
										<c:forEach items="${userList }" var="v" varStatus="i">
											<c:if test="${deptCode eq v.dept_id }">
												<dd>
													<label>
														${v.user_name }
													</label>
												</dd>
											</c:if>
 											<c:if test="${deptCode ne v.dept_id }">
												<c:if test="${not empty deptCode }"></dl></c:if>
												<c:set var="deptCode" value="${v.dept_id }" ></c:set>
												<dl>
													<dt>
														<label>
															${v.dept_name }
														</label>
													</dt>
													<dd>
														<label>
															${v.user_name }
														</label>
													</dd>
											</c:if>
											<c:if test="${(i.index+1) eq fn:length(userList) }"></dl></c:if>
										</c:forEach>
								
									</c:when>
									<c:otherwise>
										<!-- 编辑 -->
										<c:forEach items="${userList }" var="v" varStatus="i">
											<c:if test="${deptCode eq v.dept_id }">
												<dd>
													<label>
														<input type="checkbox" name="userId" value="${v.user_id }"  class="${v.dept_id }" <c:if test="${not empty v.flag}">checked="checked"</c:if> />
														${v.user_name }
													</label>
												</dd>
											</c:if>
 											<c:if test="${deptCode ne v.dept_id }">
												<c:if test="${not empty deptCode }"></dl></c:if>
												<c:set var="deptCode" value="${v.dept_id }" ></c:set>
												<dl>
													<dt>
														<label>
															<input type="checkbox" name="deptId" value="${v.dept_id }"/>
															${v.dept_name }
														</label>
													</dt>
													<dd>
														<label>
															<input type="checkbox" name="userId" value="${v.user_id }" class="${v.dept_id }" <c:if test="${not empty v.flag}">checked="checked"</c:if> />
															${v.user_name }
														</label>
													</dd>
											</c:if>
											<c:if test="${(i.index+1) eq fn:length(userList) }"></dl></c:if>
										</c:forEach>
					  					
					  					<div class="clear_both"></div>
									</c:otherwise>
								</c:choose>
							</td>
						</tr>
					</tbody>
	  			</table>
	  		</div>
        </form>
        <script type="text/javascript">
        	function showUser(){
        		var type = $('#noticeUser').val();
        		if(type == 2){
        			$('#selectTr').show();
        		}else{
        			$('#selectTr').hide();
        		}
        	}
        	
        	$(function(){
        		$("input[name='deptId']").on('click',function(){
        			$("input."+this.value+"'").attr('checked', this.checked);
        		});
        		
        		$("input[name='userId']").on('click', function(){
        			var deptId = this.className;
        			var all = $("input."+deptId+"").length;
        			var ckd = $("input."+deptId+":checked").length;
        			var checked = false;
        			if(all==ckd){
        				checked = true;
        			}
       				$("input[name='deptId'][value='"+deptId+"']").attr('checked',checked);
        		});
        		
        		
        		var initDeptCkd = function(){
        			$("input[name='deptId']").each(function(){
        				var deptId = this.value;
            			var all = $("input."+deptId+"").length;
            			var ckd = $("input."+deptId+":checked").length;
            			var checked = false;
            			if(all==ckd){
            				checked = true;
            			}
           				$(this).attr('checked',checked);
        			});
        		};
        		initDeptCkd();
        		
        	});
        </script>
  </body>
</html>